package org.example.listener;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.example.model.EventMessage;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @description: mq消费者
 * @author: 谢超
 * @date: 2023/8/24 9:58
 */
@Component
@Slf4j
//@RabbitListener(queues = "short_link.add.link.queue")
@RabbitListener(queuesToDeclare = {@Queue("short_link.error.queue")}) // 这种可以用于MQ中若无对应名称的队列/交换机的时候用，它自动创建队列
public class ShortLinkErrorMqListener {

    @RabbitHandler
    public void shortLinkHandler(EventMessage eventMessage, Message message, Channel channel) throws IOException {
        log.error("监听到告警异常情况 eventMessage:{}", eventMessage);
        log.error("监听到告警异常情况 消息内容message:{}", message);
        log.error("告警成功，发送短信");
    }
}
